/*
 * $Id: DeepSpacePanel.java 122 2009-05-12 15:54:07Z meyer@alphatec.de $
 * 
 *
 * Copyright 2009 DeltaDesk
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *   http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
 * implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package deltadesk.deepspace;

import deltadesk.gui.deltagui.layout.AbstractLayout;
import deltadesk.gui.deltagui.layout.LayoutContainer;
import deltadesk.gui.deltagui.widget.Composite;
import deltadesk.gui.deltagui.widget.SelfManagedPanel;
import deltadesk.gui.deltagui.widget.box.Box;
import deltadesk.gui.deltagui.widget.box.BoxPanel;

/**
 * DeepSpacePanel
 * 
 * @author Andreas Meyer
 * @version $Revision: 122 $
 */
public class DeepSpacePanel extends SelfManagedPanel {
	
	/** The top panel. */
	private final Box topPanel;
	
	/** The middle content panel. */
	private final BoxPanel contentPanel;

	/** The bottom panel. */
	private final Box bottomPanel;

	/**
	 * Construct the panel.
	 * 
	 */
	public DeepSpacePanel() {
		
		// set the layout
		setLayout(new DeepSpacePanelLayout());
		
		// create all panels
		topPanel = new Box();
		topPanel.setInsets(0);
		addDirect(topPanel);
		
		contentPanel = new BoxPanel(2, 2);
		addDirect(contentPanel);
		contentPanel.setBackgroundColor(null);
		
		bottomPanel = new Box();
		bottomPanel.setInsets(0);
		addDirect(bottomPanel);
	}

	/**
	 * @return the topPanel
	 */
	public Composite getTopPanel() {
		return topPanel;
	}

	/**
	 * @return the contentPanel
	 */
	public BoxPanel getContentPanel() {
		return contentPanel;
	}
	
	/**
	 * @return the bottomPanel
	 */
	public Composite getBottomPanel() {
		return bottomPanel;
	}


	/**
	 * DeepSpacePanelLayout
	 * 
	 * @author Andreas Meyer 
	 * @version $Revision: 122 $
	 */
	private class DeepSpacePanelLayout extends AbstractLayout {

		/**
		 * @see deltadesk.gui.deltagui.layout.Layout#layout(deltadesk.gui.deltagui.layout.LayoutContainer)
		 */
		public boolean layout(final LayoutContainer layoutConatiner) {
			
			if(!super.layout(layoutConatiner)) {
				return false;
			}
			
			final int li = contentPanel.getInsets().getLeft();
			final int ri = contentPanel.getInsets().getRight();
			
			topPanel.setLocation(li, 0);
			topPanel.setSize(layoutConatiner.getWidth() - (li + ri), 25);

			contentPanel.setLocation(0, 25);
			contentPanel.setSize(layoutConatiner.getWidth(), getHeight() - 50);

			bottomPanel.setLocation(li, getHeight() - 25);
			bottomPanel.setSize(layoutConatiner.getWidth() - (li + ri), 25);

			return true;
		}

	}

}
